home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / xobbs.arc / xouser.c < prev   
C/C++ Source or Header  |  1989-05-03  |  5KB  |  163 lines

  1. /* XOUSER.C User database routines for XOBBS. Jim Durham, W2XO 10-24-88 */
  2. /* Version 1.0 */
  3. /* Code released to the amateur radio community */
  4. #include "xobbs.h"
  5.  
  6. edituser(call)
  7.     char *call;
  8. {
  9.         int fd;
  10.  
  11.     struct userrecord usrrec;
  12.     int highest,recnum,fail;
  13.  
  14.     upcase(call);                /*convert the call to upper case*/
  15.  
  16.     if((fd=open(userfil,O_RDWR)) < 0)    /*try to open the user file*/
  17.     {
  18.         perror("edituser:Cant open user file");
  19.         sndupkil();
  20.     }
  21.     fail=1;
  22.     getrec(fd,0,&usrrec,sizeof(usrrec));
  23.     highest=usrrec.highest;
  24.  
  25.     for(recnum=1;recnum <= highest;recnum++){
  26.         getrec(fd,recnum,&usrrec,sizeof(usrrec));
  27.         if(!strcmp(call,usrrec.call)){
  28.             fail=0;
  29.             break;
  30.         }
  31.     }
  32.     if(fail){
  33.         sprintf(prinbuf,"***No such user*** \n");
  34.         prinout(NOFLUSH);
  35.         return 1;
  36.     }
  37.  
  38.     for(;;){
  39.         sprintf(prinbuf,"Call: %s\n",usrrec.call);
  40.         prinout(NOFLUSH);
  41.         sprintf(prinbuf,"Name: %s\n",usrrec.name);
  42.         prinout(NOFLUSH);
  43.         sprintf(prinbuf,"Type: %c\n\n",usrrec.type);
  44.         prinout(NOFLUSH);
  45.         sprintf(prinbuf,"CR to Quit, C to change call, N to change name, T to change Type\n");
  46.         prinout(FLUSH);
  47.         getline(0);
  48.         switch(inline[0]){
  49.             case 'C':
  50.             case 'c':   sprintf(prinbuf,"New Call?:");
  51.                         prinout(FLUSH);
  52.                         getline(0);
  53.                         stringcpy(usrrec.call,inline,6);
  54.                         break;
  55.             case 'N':
  56.             case 'n':   sprintf(prinbuf,"New Name?:");
  57.                         prinout(FLUSH);
  58.                         getline(0);
  59.                         stringcpy(usrrec.name,inline,20);
  60.                         break;
  61.             case 'T':
  62.             case 't':   sprintf(prinbuf,"New Type?:");
  63.                         prinout(FLUSH);
  64.                         getline(0);
  65.                         usrrec.type=inline[0];
  66.                         break;
  67.             default:    lseek(fd,(long)(-sizeof(usrrec)),1);
  68.             putrec(fd,recnum,&usrrec,sizeof(usrrec));
  69.             close(fd);
  70.                     return 0;
  71.         }
  72.     }
  73. }
  74.  
  75. getuser(call)
  76.     char *call;
  77. {
  78.     int fd;
  79.         struct userrecord usrrec;
  80.         int highest,recnum,fail;
  81.  
  82.     upcase(call);                /*convert the call to upper case*/
  83.  
  84.     if((fd=open(userfil,O_RDWR|O_CREAT,0x1b6)) < 0)/*try to open the user file*/
  85.     {
  86.         perror("getuser:Can't open User File");
  87.         sndupkil();
  88.     }
  89.     fail=1;
  90.     getrec(fd,0,&usrrec,sizeof(usrrec));
  91.     if(strcmp(usrrec.call,"******")){        /*if file never initialized*/
  92.         strcpy(usrrec.call,"******");
  93.         usrrec.highest=highest=0;
  94.     putrec(fd,0,&usrrec,sizeof(usrrec));    /*initialize file*/
  95.     }
  96.  
  97.     highest=usrrec.highest;
  98.  
  99.     for(recnum=1;recnum <= highest;recnum++){
  100.         getrec(fd,recnum,&usrrec,sizeof(usrrec));
  101.         if(!strcmp(call,usrrec.call)){
  102.             fail=0;
  103.             break;
  104.         }
  105.     }
  106.     if(fail){
  107.         strcpy(usrrec.name,"NO_NAME");        /* we dont know his name*/
  108.         strcpy(user.call,call);            /* copy call to user.call*/
  109.         strcpy(usrrec.call,call);
  110.         usrrec.highest=0;
  111.         usrrec.type='N';            /*assume novice user*/
  112.         gettim();
  113.         sprintf(usrrec.dat,"%02d%02d%02d\0",newtime->tm_year,newtime->tm_mon,newtime->tm_mday);
  114.         putrec(fd,highest+1,&usrrec,sizeof(usrrec));
  115.     getrec(fd,0,&usrrec,sizeof(usrrec));
  116.     usrrec.highest=highest+1;
  117.     putrec(fd,0,&usrrec,sizeof(usrrec));
  118.         sprintf(prinbuf,"Please use N command to enter name <N Name>\n\n");
  119.         prinout(NOFLUSH);
  120.     }
  121.     else{    /*we DO know this guy*/
  122.         strcpy(user.call,usrrec.call);        /*put the call into user data area*/
  123.         user.highest=usrrec.highest;  /* and write it to user*/
  124.         strcpy(user.name,usrrec.name);  /* and write it to user*/
  125.     user.typ=usrrec.type;
  126.         gettim();
  127.         sprintf(usrrec.dat,"%02d%02d%02d\0",newtime->tm_year,newtime->tm_mon,newtime->tm_mday);
  128.     usrrec.highest=highnum;
  129.     lseek(fd,(long)(-sizeof(usrrec)),1);
  130.         putrec(fd,recnum,&usrrec,sizeof(usrrec));  /*write updated record*/
  131.     }
  132.     close(fd);
  133. }
  134.  
  135. doname(nam)
  136.     char *nam;
  137. {
  138.     int fd,recnum,highest;
  139.     struct userrecord usrrec;
  140.     
  141.     upcase(nam);
  142.  
  143.     if((fd=open(userfil,O_RDWR)) < 0)    /*try to open the user file*/
  144.     {
  145.         sprintf(prinbuf,"Can't open %s\n",userfil);
  146.         perror(prinbuf);
  147.         sndupkil();
  148.     }
  149.     getrec(fd,0,&usrrec,sizeof(usrrec));
  150.     highest=usrrec.highest;
  151.     for(recnum=1;recnum <= highest;recnum++){
  152.     getrec(fd,recnum,&usrrec,sizeof(usrrec));
  153.         if(!strcmp(usrrec.call,user.call)){
  154.             strcpy(usrrec.name,nam);
  155.             strcpy(user.name,nam);
  156.             putrec(fd,recnum,&usrrec,sizeof(usrrec));
  157.             break;
  158.         }
  159.     }
  160.     close(fd);                              /*close the user file*/
  161. }
  162.  
  163.